package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.NetInfoDao;
import com.bestv.search.common.dataSource.DataSourceKey;
import com.bestv.search.common.model.NetInfo;
import com.bestv.search.common.service.NetInfoManager;

import java.util.List;
import java.util.Map;

public class NetInfoManagerImpl implements NetInfoManager {

    private NetInfoDao netInfoDao;

    @Override
    public NetInfo getInfoByNetId(DataSourceKey key, String netId) {
        return netInfoDao.getInfoByNetId(netId);
    }

    @Override
    public NetInfo getInfoByInfoId(DataSourceKey key, long info_id) {
        return netInfoDao.getInfoByInfoId(info_id);
    }

    @Override
    public void saveOrUpdate(DataSourceKey key, NetInfo netInfo) {
        netInfoDao.saveOrUpdate(netInfo);
    }

    @Override
    public void saveOrUpdateList(DataSourceKey key, List<NetInfo> netInfos) {
        for (NetInfo info : netInfos) {
            netInfoDao.saveOrUpdate(info);
        }
    }

    @Override
    public void saveReference(DataSourceKey key, long info_id, long netInfo_id) {
        if (!netInfoDao.existReference(info_id, netInfo_id)) {
            netInfoDao.saveReference(info_id, netInfo_id);
        }
    }

    @Override
    public void saveReferenceList(DataSourceKey key, List<Map.Entry<Long, Long>> mappingList) {
        for (Map.Entry<Long, Long> entry : mappingList) {
            if (!netInfoDao.existReference(entry.getKey(), entry.getValue())) {
                netInfoDao.saveReference(entry.getKey(), entry.getValue());
            }
        }
    }

    @Override
    public List<NetInfo> getAll(DataSourceKey key) {
        return netInfoDao.getAll();
    }

    @Override
    public List<String> getAllName(DataSourceKey key, int start, int limit) {
        return netInfoDao.getAllName(start, limit);
    }

    @Override
    public int getNameCount(DataSourceKey key) {
        return netInfoDao.getNameCount();
    }

    public NetInfoDao getNetInfoDao() {
        return netInfoDao;
    }

    public void setNetInfoDao(NetInfoDao netInfoDao) {
        this.netInfoDao = netInfoDao;
    }
}